//
//  LSSettingAndHelpTableViewController.m
//  ZLFastDoctor
//
//  Created by 李宗帅 on 16/5/22.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "LSSettingAndHelpTableViewController.h"
#import "LSOpinionTableViewController.h"
#import "LSSymbolControllerViewController.h"
#import "LSCorrectViewController.h"
#import "XZGRegisterViewController.h"
#define LSSettingAndHelpTableViewReusableIdentifier @"LSSettingAndHelpTableViewReusableIdentifier"

@interface LSSettingAndHelpTableViewController ()

//懒加载数据源
@property (nonatomic,strong) NSArray *settingAndHelp;
@end

@implementation LSSettingAndHelpTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置标题
    self.title = @"设置与帮助";
    
    //重写返回按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_button_back_01"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];

//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"nav_button_back_01"] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftBtn)];
//    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:LSSettingAndHelpTableViewReusableIdentifier];
    
}

//重写返回按钮,判断是否打开菜单侧滑
- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
    [NQNavVc judgeMenuOpen];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.settingAndHelp.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:LSSettingAndHelpTableViewReusableIdentifier forIndexPath:indexPath];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:LSSettingAndHelpTableViewReusableIdentifier];
    }
    
    cell.textLabel.text = self.settingAndHelp[indexPath.row];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.textLabel.font = [UIFont boldSystemFontOfSize:16.0f];
    
    
    return cell;
}

//cell选中的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //意见反馈
    LSOpinionTableViewController *OC = [[LSOpinionTableViewController alloc]init];

    //加号符号说明,里边就是一个webView
    LSSymbolControllerViewController *SC = [[LSSymbolControllerViewController alloc]init];
    //修改密码
    LSCorrectViewController *CC = [[LSCorrectViewController alloc]init];
    
    switch (indexPath.row) {
        case 0:
            
            [self.navigationController pushViewController:OC animated:YES];
            
            break;
        case 1:
            
            [self.navigationController pushViewController:SC animated:YES];
            break;
        case 2:
            [self.navigationController pushViewController:CC animated:YES];
            break;
        case 3:
            
            [self clickExitLogin];
            break;
            
        default:
            break;
    }
}

//懒加载
- (NSArray *)settingAndHelp {
    if (_settingAndHelp == nil) {
        
        NSMutableArray *settingAndHelp = [NSMutableArray array];
        
        settingAndHelp = [NSMutableArray arrayWithObjects:@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户", nil];
        
        _settingAndHelp = settingAndHelp;
    }
    
    return _settingAndHelp;
}

- (void)clickExitLogin {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"你确定要退出么?" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *exitLogin = [UIAlertAction actionWithTitle:@"注销" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        //在这里注销登录信息 改变全局登录状态
        XZGRegisterViewController *registerVc = [[XZGRegisterViewController alloc] init];
        UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:registerVc];
        navVc.navigationBar.backgroundColor = NQNavColor;
        [self presentViewController:navVc animated:YES completion:nil];
        [self.navigationController popToRootViewControllerAnimated:YES];
    }];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alert addAction:exitLogin];
    [alert addAction:cancel];
    
    [self presentViewController:alert animated:YES completion:nil];
}
@end
